﻿using System;

namespace _5E.Utils.DbHelper.EasySQL
{
    class EasyDbTable
    {
        #region 变量

        private const string WHERE_SEPARATOR = " AND ";
        
        #endregion

        #region 属性

        private string m_TableName = null;
        public string TableName { get { return m_TableName; } }

        private EasyDbColumn[] m_Columns = null;
        public EasyDbColumn[] Columns { get { return m_Columns; } }

        private string m_PKWhereSQL = null;
        public string PKWhereSQL
        {
            get
            {
                if (string.IsNullOrEmpty(m_PKWhereSQL))
                {
                    var pkColumns = Array.FindAll(Columns, c => c.ColumnType == EasyDbColumnType.PK);
                    var conditions = Array.ConvertAll(pkColumns, pk => string.Format("={0}", pk.PropertyName));
                    m_PKWhereSQL = string.Join(WHERE_SEPARATOR, conditions);
                }
                return m_PKWhereSQL;
            }
        }

        #endregion

        #region 构造函数

        public EasyDbTable(string tableName, EasyDbColumn[] columns)
        {
            m_TableName = tableName;
            m_Columns = columns;
        }

        #endregion

        #region 方法

        #endregion
    }
}
